<template>
  <div :class="['freeLoot', state.active === 0 ? 'freeLoot_1' : 'freeLoot_2']">
    <div class="image-banner">
      <div class="banner_img">
        <img v-lazy="'/imgs/freeLoot/freeLoot_banner.webp'" :key="'freeLoot_banner'" alt="">
      </div>
      <div class="banner_text">
        <img v-lazy="'/imgs/freeLoot/freeLoot_text.webp'" :key="'freeLoot_text'" alt="">
      </div>
      <div class="time">
        <span>{{ t('free_loot_activity_time') }}：2024.1.1 ~ 2024.6.30</span>
      </div>
    </div>

    <div class="self">
      <div class="profile">
        <div class="user">
          <img class="avatar" v-lazy="'/imgs/head_icons/1003.webp'" :key="'1003'" alt="avatar">
          <div class="info">
            <div class="account">{{ t('free_loot_ranking_username') }}：User1234</div>
            <div class="ranking">{{ t('free_loot_ranking_today') }}：{{ freeTreasureInfoData.rank === -1 ? '--' :
              freeTreasureInfoData.rank || '--' }}</div>
          </div>
        </div>
        <div class="coins">
          <span>{{ t('free_loot_ranking_trial_coin') }}</span>
          <div class="coin-amount">
            <img v-lazy="'/imgs/freeLoot/gold.webp'" :key="'gold'" alt="coin">
            <span>{{ freeTreasureInfoData.score || '--' }}</span>
          </div>
        </div>
      </div>
    </div>


    <!--  tabBar  -->
    <div class="content">
      <div class="tab">
        <span v-shrink-on-click :class="state.active == i ? 'btn' : ''" v-for="(tab, i) in tabList" :key="i"
          @click="changeTab(i)">{{
            tab.name
          }}</span>
      </div>
      <div class="reg-box">
        <FreeGame v-if="state.active === 0" />
        <HistoricalRankings v-else />
      </div>


    </div>

    <div class="tabs" v-if="state.active === 0">
      <div class="title">{{ t('free_loot_rule_events') }}</div>
      <div class="text">
        {{ t('free_loot_rule_events_text') }}
      </div>
    </div>

    <div class="tabs" v-if="state.active === 0">
      <div class="title">{{ t('free_loot_rule_events') }}</div>
      <div class="text">
        <p>{{ t('free_loot_rule_ranking_text_1') }}</p>
        <p>{{ t('free_loot_rule_ranking_text_2') }}</p>
        <p style="margin-top: 20px;">{{ t('free_loot_rule_flow') }}</p>
        <p>{{ t('free_loot_rule_flow_text_1') }}</p>
        <p>{{ t('free_loot_rule_flow_text_2') }}</p>
      </div>
    </div>

    <div class="footer" v-if="state.active === 1">
      <img v-lazy="'/imgs/head_icons/1003.webp'" :key="'1003'" alt="">
      <div class="info">
        <div class="ranking">
          <p>{{ t('free_loot_ranking_trial_ranking') }}</p>
          <p style="color: #fff">2</p>
        </div>
        <div class="line">
          <img v-lazy="'/imgs/wallet/line.webp'" :key="'line'" alt="">
        </div>
        <div class="glod">
          <p>{{ t('free_loot_ranking_trial_coin') }}</p>
          <p style="color: rgba(228, 57, 57, 1)">20000</p>
        </div>
        <div class="line">
          <img v-lazy="'/imgs/wallet/line.webp'" :key="'line'" alt="">
        </div>
        <div class="award">
          <p>{{ t('free_loot_ranking_trial_award') }}</p>
          <p style="color: rgba(255, 159, 105, 1);">20000</p>
        </div>
      </div>
    </div>

  </div>
</template>

<script setup lang="ts">

import { onBeforeMount, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
import FreeGame from "@/views/freeLoot/freeGame.vue";
import HistoricalRankings from "@/views/freeLoot/historicalRankings.vue";
import PKwebsocket from "@/lolo/Ws";
import { NetPacket } from '@/netBase/NetPacket';

const { t } = useI18n();


const state: any = reactive({
  active: 1,
})
const tabList = [
  { name: t('free_loot_game'), value: 0 },
  { name: t('free_loot_ranking'), value: 1 }
]

const changeTab = (tabId: number) => {
  state.active = tabId;
};


const reqFreeTreasureInfo = () => {
  const req_free_treasure_info = NetPacket.req_free_treasure_info();
  PKwebsocket.instance.send(req_free_treasure_info, true, {
    callbackName: 'msg_notify_free_treasure_info',
    callback: handleFreeTreasureInfo
  })
}


const freeTreasureInfoData: any = ref({})
const handleFreeTreasureInfo = (res: any) => {

  // alert('??asdasda?')
  console.log(res, '-res-');
  freeTreasureInfoData.value = res
  // arrData = data.gameIds || []
  //
  if (res.gameIds) {

  }

};

const freeLootRankingData: any = reactive({
  list: [],
  roundid: 0,
  roundidOptions: [],
  page: 1,
  pageSize: 5
})

// 获取 排名信息
const handleGoldTable = (res: any) => {
  let data = res.info.splice(1, res.info.length);
  if (data.length === 1) return (freeLootRankingData.list = []);
  if (freeLootRankingData.page !== 1)
    return freeLootRankingData.list.push([...data]);
  freeLootRankingData.list = data;
};

onBeforeMount(() => {
  console.log(handleGoldTable)
  reqFreeTreasureInfo()
})


</script>


<style scoped lang="scss">
.freeLoot {
  width: 100%;
  overflow-x: hidden;

  &.freeLoot_1 {
    height: calc(var(--vh) * 100 - 61px)
  }

  &.freeLoot_2 {
    height: calc(var(--vh) * 100 - 61px - 72px)
  }

  overflow-y: auto;

  .image-banner {
    margin-top: 30px;
    width: 100%;
    height: 264px;
    background: url("/imgs/freeLoot/freeLoot_bg.webp") no-repeat center;
    background-size: 100%;

    .banner_img {
      display: flex;
      justify-content: center;
    }

    .banner_text {
      display: flex;
      transform: translateY(-30px);
      justify-content: center;

      img {
        width: 190px;
        height: 86px;
      }
    }

    .time {
      width: 234px;
      height: 24px;
      margin: 0 auto;
      line-height: 24px;
      border-radius: 20px;
      border: 1px solid #1260FF;
      background: #1F2032;
      transform: translateY(-30px);

      span {
        padding: 0 10px;
        color: #fff;
      }
    }
  }

  .self {
    width: 347px;
    height: 80px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    transform: translateY(-25px);
    border-radius: 8px;
    background: linear-gradient(95deg, #FA397E 0%, #FF852D 99.32%), var(---, #131232);

    /* 新皮/弹窗背景 */
    box-shadow: 0.5px 0.5px 1px 0 #2E296B inset;
    padding: 12px 10px;
    border-radius: 10px;

    .profile {
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;

      .user {
        display: flex;
        align-items: center;

        .avatar {
          width: 60px;
          height: 60px;
          border-radius: 50%;
          margin-right: 10px;
        }

        .info {
          color: #FFF;
          font-family: "PingFang SC";
          font-size: 14px;
          font-style: normal;
          font-weight: 400;
          line-height: normal;

          .account {
            margin-bottom: 5px;
          }
        }
      }


      .coins {
        width: 74px;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 2px;
        color: #fff;

        span {
          color: #FFF;
          text-align: center;
          font-family: "PingFang SC";
          font-size: 14px;
          font-style: normal;
          font-weight: 400;
          line-height: normal;
        }

        .coin-amount {
          display: flex;
          align-items: center;
          padding-right: 7px;
          margin-top: 9px;
          height: 22px;
          border-radius: 4px;
          background: rgba(16, 14, 38, 0.60);

          img {
            width: 18px;
            height: 18px;
            margin-right: 2px;
          }

          span {
            color: #FFF;
            font-family: "PingFang SC";
            font-size: 12px;
            font-weight: 600;
          }
        }
      }
    }

  }

  .content {
    transform: translateY(-15px);
    box-sizing: border-box;
    padding: 14px 8px 0;
    width: 347px;
    min-height: 427px;
    margin: 0 auto;
    border-radius: 12px;
    background: rgba(19, 18, 50, 1);

    /* 新皮/弹窗背景 */
    box-shadow: 0.5px 0.5px 1px 0px #2E296B inset;

    .tab {
      width: 100%;
      height: 44px;
      display: flex;
      justify-content: space-around;
      align-items: center;
      color: #c0c2db;
      margin: 0 auto;
      font-size: 12px;
      //background: url("/imgs/btn/tabBtn.webp") no-repeat;
      //background-size: cover;
      padding: 2px;
      border-radius: 8px;
      border: 1px solid var(---, #1D1C3C);
      background: var(---1, #100E26);

      .btn {
        width: 152px;
        height: 40px;
        color: #fff;
        border-radius: 8px;
        background: linear-gradient(180deg, #5567FF 0%, #9E1EFF 100%);
        box-shadow: 0.5px 0.5px 1px 0px #9B9EFF inset;
      }

      >span {
        width: 120px;
        height: 36px;
        display: flex;
        justify-content: center;
        align-items: center;

      }
    }

    .reg-box {
      margin-top: 18px;
    }
  }

  .tabs {
    width: 347px;
    margin: 0 auto 10px;
    border-radius: 12px;
    background: var(---, #131232);
    /* 新皮/弹窗背景 */
    box-shadow: 0.5px 0.5px 1px 0px #2E296B inset;
    color: #fff;

    .title {
      padding: 10px;
      border-radius: 12px 12px 0 0;
      width: 347px;
      height: 40px;
      color: #FFF;
      font-family: "PingFang SC";
      font-size: 14px;
      font-weight: 600;
      background: #282845;
      box-shadow: 0.5px 0.5px 1px 0px #2E296B inset;
    }

    .text {
      color: #FFF;
      font-family: "PingFang SC";
      font-size: 12px;
      font-weight: 400;
      padding: 15px 10px;
    }
  }


  .footer {
    position: fixed;
    display: flex;
    align-items: center;
    padding: 0 14px;
    justify-content: space-between;
    width: 375px;
    height: 72px;
    background-color: #fff;
    bottom: 0;
    left: 0;
    box-shadow: 0.5px 0.5px 1px 0px rgba(46, 41, 107, 1) inset;
    background-color: rgba(19, 18, 50, 1);

    img {
      width: 42px;
      height: 42px;
    }

    .info {
      display: flex;
      align-items: center;

      p {
        color: rgba(198, 196, 245, 1);
        text-align: center;
      }

      .line {
        margin: 0 12px;

        img {
          width: 2px;
          height: 30px;

          img {
            width: 100%;
            height: 100%;
          }
        }
      }
    }

  }
}
</style>
